import './assets/reset.css'
import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import Vant from 'vant'
import 'vant/lib/index.css'
import '@vant/touch-emulator'

// Capacitor 导入
import { App } from '@capacitor/app'
import { StatusBar, Style } from '@capacitor/status-bar'
import { Capacitor } from '@capacitor/core'

import AppComponent from './App.vue'
import router from './router'

const app = createApp(AppComponent)

app.use(createPinia())
app.use(router)
app.use(Vant)

app.mount('#app')

// Capacitor 初始化
if (Capacitor.isNativePlatform()) {
  // 设置状态栏：白色背景，黑色文字
  // 注意：Style.Light 表示状态栏文字为黑色（用于浅色背景）
  // Style.Dark 表示状态栏文字为白色（用于深色背景）
  StatusBar.show().then(() => {
    StatusBar.setBackgroundColor({ color: '#ffffff' })
    StatusBar.setStyle({ style: Style.Light })
  }).catch(() => {})
  
  // 处理 Android 返回按钮
  App.addListener('backButton', ({ canGoBack }: { canGoBack: boolean }) => {
    if (canGoBack) {
      window.history.back()
    } else {
      App.exitApp().catch(() => {})
    }
  }).catch(() => {})
}
